const fs = require('fs') // 文件模块
export default function auto(path = './docs') {
    let sidebar = []
    const files = fs.readdirSync(path)
    files.forEach((item)=>{
        let args = fs.statSync(`${path}/${item}`).isDirectory()
        if(args && !isNaN(parseInt(item.split('.')[0]))){
            let items = []
            const nextFiles = fs.readdirSync(`${path}/${item}`)
            nextFiles.forEach((nextItem)=>{
                let nextArgs = fs.statSync(`${path}/${item}/${nextItem}`).isFile()
                let boolean = nextItem.split('.')[nextItem.split('.').length-1] === 'md'
                if(nextArgs && boolean)
                    items.push({
                        text: nextItem.split('.')[1],
                        link: `/${item}/${nextItem}`
                    })
            })
            // sidebar[`/${item}/`] = [{
            //     text: item.split('.')[1],
            //     items
            // }]
            sidebar.push({
                text: item.split('.')[1],
                collapsible: true,
                collapsed: true,
                items
            })
        }
    })
    return sidebar
}